package com.tarena.lbs.basic.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.basic.web.service.LoginService;
import com.tarena.lbs.pojo.passport.param.AdminLoginParam;
import com.tarena.lbs.pojo.passport.param.UserLoginParam;
import com.tarena.lbs.pojo.passport.vo.LoginVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class LoginController {
    //登录请求
    @Autowired
    private LoginService loginService;
    @PostMapping("/passport/admin/login")
    public Result<LoginVO> adminLogin(AdminLoginParam param) throws BusinessException {
        //调用业务层处理登录 只要控制层要返回给前端VO,所有的vo都在业务层封装
        //如果接口需要返回给前端数据,必定封装VO
        //如果接口必须要返回给前端数据,Void比如新增数据 修改数据
        LoginVO vo=loginService.doLogin(param);
        return new Result<>(vo);
    }

    //手机小程序登录
    @PostMapping("/passport/user/login")
    public Result<LoginVO> userLogin(UserLoginParam param)
        throws BusinessException{
        LoginVO vo=loginService.doLogin(param);
        return new Result<>(vo);
    }
}
